#delimit;
set more off;

set mem 500m;

set logtype text;

log using /home/dnc2101/Accidental_Deaths/Vital_Stats/Summary_Stats_Types_Accidents/make_drug_OD_vars_ICD_10.log, replace;



/********************************************************************************************************************/
*
* This do file takes the Vital Stats Mortality data, and creates a dataset that has a count of the number of fatal 
* drug overdoses in occur in each state in each year.  These counts can be used along with Census data on 
* state-year populations to generate the rate of fatal drug overdoses that occurs in each state in each year.  This 
* do file creates these counts for the years 1999 through 2004, the years of the data that use ICD-10 coding on cause 
* of death;  a seperate do file does the same exact task for the years 1981 through 1998, the years of data which 
* use ICD-9 coding on cause of death
*
*
* Program by Dan Carvell, written between Fall 2008 and Spring 2010.  
*
*********************************************************************************************************************/





use "/home/dnc2101/Accidental_Deaths/Vital_Stats/Data_For_Appending/Injury_Deaths_99_04.dta", clear;

gen drug_OD=0;
replace drug_OD=1 if ucr358==420;

label variable drug_OD "=1 if death is a drug overdose";



collapse (sum) drug_OD, by(fipsstr year); 


**sort the data so that the merge with other data goes OK;

sort fipsstr year;


save "/home/dnc2101/Accidental_Deaths/Vital_Stats/Cleaned_Datasets/Drug_OD_Counts_99_04.dta", replace;

** export this into xml format so I can put the count of drug overdoses into the raw excel data by hand, and browse this data  ;
** for comparison with data on all types of fatal poisonings, not just drug overdoses, from the CDC's WISQARs dataset  ;

xmlsave "/home/dnc2101/Accidental_Deaths/Vital_Stats/Cleaned_Datasets/Drug_OD_Counts_99_04.xml", doctype(excel) replace;










** Now redo this process, but with collapsing at the year level rather than state-year level, to get a national-level rate for a figure for the paper;


use "/home/dnc2101/Accidental_Deaths/Vital_Stats/Data_For_Appending/Injury_Deaths_99_04.dta", clear;



gen drug_OD=0;
replace drug_OD=1 if ucr358==420;

label variable drug_OD "1 if death is a drug overdose";



collapse (sum) drug_OD, by(year); 


**sort the data so that the merge with other data goes OK;

sort year;


save "/home/dnc2101/Accidental_Deaths/Vital_Stats/Cleaned_Datasets/Drug_OD_Counts_99_04_National.dta", replace;

** export this into xml format so I can put the count of drug overdoses into the raw excel data by hand;

xmlsave "/home/dnc2101/Accidental_Deaths/Vital_Stats/Cleaned_Datasets/Drug_OD_Counts_99_04_National.xml", doctype(excel) replace;




log close;











